<template>
	<view class="">
		<u-calendar @close="showCalendar=false" @confirm="confirmCalendar" :show="showCalendar" :minDate="date_start" :monthNum="36"></u-calendar>
		<w-navbar :isBack="false">
			<template #w-navbar-title>
				<view class="top_box">
					<view class="left">
						<u-search @change="changeSearch" placeholder="搜索关键字" v-model="keyword"></u-search>
					</view>
				</view>
			</template>
		</w-navbar>
		<w-container @scrolltolower="scrolltolower"  isTabbar>
			<template>
				<view class="content">
					<view class="fr-ac-jsb" style="box-sizing: border-box;padding: 20rpx 4vw;position: sticky;top: 0;background-color: white;z-index: 99;">
						<view class="class_name bold fs-18">
							{{category_choose.name}}
						</view>
						<view class="fr-ac">
							<view @click="clearDate" class="" style="color: #81c4d2;">
								清除
							</view>
							<view @click="showCalendar = true" class="date-btn ml-30">
								{{date?date:'筛选日期'}}
							</view>
						</view>
						
					</view>
					<view class="right">
						
						
						<view class="frw">
							<view class="goods_item fc-jc" v-for="(item,index) in list" :key="item.id">
								<!-- <view class="goods_img">
									<image :src="ossURL + item.image" mode="widthFix"></image>
								</view> -->
								<view class="goods_name">
									商品名称：{{item.goods_name}}
								</view>
								<view class="mt-20">
									手机号：{{item.mobile}}
								</view>
								
								<view class="fr-ae-jsb">
									<view class="">
										<view class="mt-20">
											单价￥{{item.price}}
										</view>
										<view class="mt-20">
											数量：{{item.goods_num}}
										</view>
										<view class="mt-20">
											总计￥{{ (item.price * item.goods_num).toFixed(2) }}
										</view>
									</view>
									<view class="">
										日期：{{item.date}}
									</view>
								</view>
								
								<view v-if="item.images && item.images.length" class="fr-ae-jsb mt-20">
									<view class="">
										
									</view>
									<view class="image-btn" @tap="previewImage(index)">
										查看图片
									</view>
								</view>
								
								
							</view>
						</view>
						
					</view>
				</view>
			</template>
		</w-container>
		<w-tabbar></w-tabbar>
	</view>
</template>

<script>
	import {
		debounce
	} from '@/utils/common'
	export default {
		data() {
			return {
				search_title:'',
				
				category_list:[{
					id:0,
					name:'登记列表',
				}],
				category_choose:{
					id:0,
					name:'登记列表',
				},
				goods_list:[],
				
				is_edit_goods:'',
				is_see_special:'',
				price_level:'',
				
				list:[],
				keyword:'',
				date:'',
				showCalendar:false,
				
				date_start:'',
				
				limit:20,
				last_limit:0,
				page:1,
			}
		},
		watch: {
		
		},
		async onLoad() {
			const currentYear = new Date().getFullYear();
			this.date_start = (currentYear-1) + '-1-1'
			this.loadData()
		},
		onShow() {
		},
		methods: {
			scrolltolower(){
				console.log('12312312')
				if(this.limit == this.last_limit){
					this.page ++
					this.loadData()
				}else{
					uni.showToast({
						title:'暂无更多',
						icon:'none'
					})
				}
			},
			//预览图片
			previewImage: function(index) {
				uni.previewImage({
					current: 0,
					urls: this.list[index].images
				});
			},
			confirmCalendar(e){
				console.log(e,'eeeeee')
				this.date = e[0]
				this.showCalendar = false
				this.initData()
				this.loadData()
			},
			async loadData() {
				uni.showLoading({
					title: '飞速加载中...'
				})
				const res = await this.$http({
					url: '/api/Sign/getSignList',
					data: {
						keyword:this.keyword,
						date:this.date,
						limit:this.limit,
						page:this.page
					}
				})
				uni.hideLoading()
				if (res.code == 1) {
					this.last_limit = res.data.list.length
					this.list = this.list.concat(res.data.list)
				}else{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
			},
			async search_goods() {
				let source
				if(this.search_title == ''){
					source = 0
				}else{
					this.category_choose = this.category_list.find((item)=>item.id == 0)
					source = 1
				}
				uni.showLoading({
					title: '飞速加载中...'
				})
				const res = await this.$http({
					url: '/addons/shop/api.goods/search_goods',
					data: {
						title:this.search_title,
						source:source
					}
				})
				uni.hideLoading()
				if (res.code == 1) {
					this.goods_list = res.data.goods_list
				}else{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
			},
			categoryChoose(item){
				this.category_choose = item
				this.goods_list = item.goods
				this.search_title = ''
				if(item.id == 0){
					return this.search_goods()
				}
			},
			
			goGoodsDetail(item){
				uni.navigateTo({
					url:`/pages/goods/details?goods_id=${item.id}`
				})
			},
			goGoodsEdit(item){
				uni.navigateTo({
					url:`/pages/goods/edit?goods_id=${item.id}`
				})
			},
			initData(){
				this.page = 1
				this.last_limit = 0
				this.list = []
			},
			changeSearch:debounce(function(){
				this.initData()
				this.loadData()
			}),
			
			clearDate(){
				this.date = ''
				this.initData()
				this.loadData()
			}
		}
			
	}
</script>

<style lang="scss" scoped>
	.top_box{
		padding-top: 10rpx;
		position: relative;
		width: 100%;
		height: 90%;
		display: flex;
		align-items: center;
		
		.left{
			margin: 0 20rpx;
			margin-left: 40rpx;
			height: 100%;
			width: 100%;
			image{
				margin: 5% 0;
				width: 100%;
				height: 80%;
			}
		}
		.right{
			position: relative;
			margin: 5% 0;
			height: 90%;
			display: flex;
			align-items: center;
			border: 2rpx solid rgb(54,48,52);
			width: 100%;
			border-radius: 10rpx;
			
			input{
				margin: 0 12rpx;
			}
			.iconfont{
				margin: 0 12rpx;
			}
		}
	}
	
	.content{
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		position: relative;
		
		
		.left{
			width: 28%;
			height: 100%;
			overflow: scroll;
			
			.class_item{
				margin: 30rpx 0;
				
				.class_item_name{
					text-align: center;
					margin: 16rpx 0;
				}
				.line{
					margin: 0 38%;
					width: 24%;
					height: 6rpx;
					background-color: #eee;
				}
			}
			
			.class_item_check{
				transition: all 0.3s;
				font-weight: bold;
				transform: scale(1.2);
			}
			.class_line_check{
				transition: all 0.3s;
				background-color: $theme-color !important;
			}
			
		}
		
		.right{
			width: 100%;
			height: 100%;
			overflow: scroll;
			background-color: rgb(250,250,252);
			
			.class_name{
				margin: 30rpx 0;
				font-weight: bold;
				font-size: 36rpx;
			}
			
			.goods_item{
				width: 92%;
				margin: 20rpx 4%;
				background-color: white;
				box-sizing: border-box;
				padding: 30rpx;
				border-radius: 12rpx;
				box-shadow: 2rpx 2rpx 12rpx #d1e9ee;
				
				.goods_img{
					width: 100%;
					image{
						width: 100%;
					}
				}
				
				.goods_name{
					word-break: break-all;
					margin: 12rpx 0;
					font-size: 34rpx;
					font-weight: bold;
				}
				
				.goods_price{
					font-size: 24rpx;
				}
				
				.iconfont{
				}
			}
		}
	}
	
	.date-btn{
		padding: 8rpx 32rpx;
		border-radius: 12rpx;
		color: #fff;
		background-color: $theme-color;
	}
	
	.image-btn{
		border-radius: 12rpx;
		padding: 8rpx 28rpx;
		color: #fff;
		background-color: $theme-color;
	}
</style>